package parts;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBC {
    public Connection create(){
        String url="jdbc:mysql://localhost:3306/hospitalappoint?useSSL=false&serverTimezone=CST&characterEncoding=UTF-8";
        String user="root";
        String password="2020";
        Connection con=null;
        try {
            con=DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        if(con!=null){
            System.out.println("数据库连接成功");
        }else {
            System.out.println("数据库连接失败");
        }
        return con;
    }
    public void close(Connection con)throws Exception{
        if(con!=null) {
            con.close();
            System.out.println("关闭数据库连接");
        }
    }
}
